package com.nwu.common.config;


import com.nwu.common.interceptor.UserInforInterceptor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
@ConditionalOnClass(DispatcherServlet.class)//针对spring的类，这样只有微服务会自动装配
public class MvcConfig implements WebMvcConfigurer {
    /**
     * 这个是开启拦截器，但是其他微服务不能自动装配，所以需要改配置
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new UserInforInterceptor());
    }
}
